home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 127 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c,comp.std.c
  4. Subject: Re: Trouble with file return code.
  5. Date: 17 Jan 1996 15:02:06 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan17080206@qcd.lanl.gov>
  8. References: <tcpnntpd.16.1.10.20.22.42.2781597121.333610@the-fix.sos.on.ca>
  9.     <4d3h96$9fl@news.iag.net> <DLAv0C.GqF@thinkage.on.ca>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: atbowler@thinkage.on.ca's message of Wed, 17 Jan 1996 00:36:12 GMT
  14.  
  15. --text follows this line--
  16.  
  17. Note crosspost to comp.std.c.
  18.  
  19. In article <DLAv0C.GqF@thinkage.on.ca> atbowler@thinkage.on.ca (Alan
  20. Bowler) writes: 
  21. <snip>
  22.    In article <4d3h96$9fl@news.iag.net> jatmon@iag.net (John R Buchan) writes:
  23.    >      
  24.    >   /* Of course, you'll want to do better i/o testing, but basically */
  25.    >   while( fread(buf, sizeof(buf), 1, ptr) == 1)
  26.  
  27.    I know you covered yourself with a disclaimer, but this one is very
  28.    dicy.  If fread get an EOF part way though the "sizeof buf" bytes
  29.    it may return 0 or 1.  (does the library round up or down?).
  30.  
  31. `The fread function returns the number of elements succesfully
  32. read'. Do you consider reading less than the number of bytes as a
  33. successful read of an element? 
  34.  
  35.    I suggest
  36.  
  37.       while(sizeof buf == (count = fread(buf, 1, sizeof(buf), ptr))) {
  38.          /* play with the record */
  39.       }
  40.       if (0 != count) 
  41.        error("last record was incomplete. and had only %d bytes", count);
  42.  
  43.    I watch this one carefully because we bit a set of users once when
  44.    we changed the round up/down choice in our library.
  45.  
  46. Is `rounding up' ANSI conformant?
  47.  
  48. Cheers
  49. Tanmoy
  50. --
  51. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  52. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  53. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  54. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  55. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  56. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  57.